package com.geping.etl.common.repository;

import java.util.List;

import com.geping.etl.common.entity.Sys_Menu;
import io.swagger.models.auth.In;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import com.geping.etl.common.entity.Sys_Subject;

@Repository
public interface Sys_SubjectRepository extends PagingAndSortingRepository<Sys_Subject, Integer>,JpaSpecificationExecutor<Sys_Subject>{
	@Query("select s from Sys_Subject s order by id ASC")
	public List<Sys_Subject> findAllSubject();
	
	@Query(value="SELECT * FROM sys_subject a"
	       +" RIGHT JOIN (SELECT DISTINCT c.SUBJECT_ID FROM sys_auth_role c RIGHT JOIN  (SELECT * FROM sys_auth_role_user saru where saru.USER_ID = ?1) d ON c.ID = d.ROLE_ID) b ON a.ID = b.SUBJECT_ID order by a.ID ASC",nativeQuery=true)
	public List<Sys_Subject> findSubjectByUserId(Integer userId);
	
	@Query("select s.id from Sys_Subject s")
	public List<Integer> getAllId();

	// 查询系统的名字和id
	@Query("select new Sys_Subject(s.id,s.subjectName) from Sys_Subject s where 1=1 and s.id<>1 and s.id<>2 ")
	public List<Sys_Subject> getAllIdName();


	@Query("select s from Sys_Menu s where s.url=?1 and s.subjectId=?2")
	public List<Sys_Menu> findAllMenu(String url,String subjectId);

}
